package com.example.tourism.controller;

import com.example.tourism.pojo.Result;
import com.example.tourism.pojo.po.Coupon;
import com.example.tourism.pojo.vo.req.CommentReq;
import com.example.tourism.pojo.vo.req.GetOrderListVo;
import com.example.tourism.pojo.vo.req.OrdersReq;
import com.example.tourism.service.OrderService;
import com.example.tourism.service.impl.SeckillServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.example.tourism.pojo.Result.success;

@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
     private SeckillServiceImpl seckillService;

    @GetMapping("/getOrderHotel")
    public Result getOrderHotel(String roomId){
        return orderService.getOrderHotel(roomId);
    }

    @GetMapping("/getCustomers")
    public Result getCustomers(String userId){
        return orderService.getCustomers(userId);
    }

    @GetMapping("/getOrderCoupon")
    public Result getCoupons(String userId,String roomId){
        return orderService.getCoupons(userId,roomId);
    }

    // 生成订单
    @PostMapping("/createOrder")
    public Result createOrder(@RequestBody OrdersReq ordersReq){
      //  return orderService.createOrder(userId,roomId,couponId,customerId);
        return  orderService.createOrder(ordersReq);
    }

    @GetMapping("/getOverOrdersTime")
    public Result getOverOrdersTime(String roomId){
        return orderService.getOverOrdersTime(roomId);
    }

    @PostMapping("/hotelGetOrderData")
    public Result hotelGetOrderData(@RequestBody GetOrderListVo  getOrderListVo){
        return orderService.hotelGetOrderData(getOrderListVo);
    }

    @PostMapping("/clientGetOrderData")
    public Result clientGetOrderData(@RequestBody GetOrderListVo  getOrderListVo){
        return orderService.clientGetOrderData(getOrderListVo);
    }

    @PostMapping("/cancelOrder")
    public Result cancelOrder(String orderUid){
        return orderService.cancelOrder(orderUid);
    }

    @PostMapping("/submitComment")
    public Result submitComment(@RequestBody CommentReq comment) {
        return orderService.submitComment(comment);
    }

    @PostMapping("/insertCoupon")
    public Result insertCoupon(@RequestBody Coupon coupon, String userId){
        return orderService.insertCoupon(coupon,userId);
    }

    @GetMapping("/getHotelCoupons")
    public Result getHotelCoupons(String userId){
        return orderService.getHotelCoupons(userId);
    }

    @GetMapping("/getHotelCouponsByHotelId")
    public Result getHotelCouponsByHotelId(String hotelId){
        return orderService.getHotelCouponsByHotelId(hotelId);
    }

    @PostMapping("/grabCoupon")
    public Result grabCoupon(String couponId,String userId){
        System.out.println("couponId:"+couponId+"userId:"+userId);
        return  seckillService.attemptSeckill(couponId,userId);
    }

    @GetMapping("/getMyCoupons")
    public Result getMyCoupons(String userId){
        return orderService.getMyCoupons(userId);
    }



}


